package cn.sc.allinpay.allfavour.business.cashiersell;

import com.alibaba.fastjson.JSONObject;

import java.util.List;

import cn.pai.mvp.callback.MpCallBack;
import cn.sc.allinpay.allfavour.base.connect.http.AppRequest;
import cn.sc.allinpay.allfavour.base.connect.http.RequestManager;
import cn.sc.allinpay.allfavour.base.model.BaseModel;
import cn.sc.allinpay.allfavour.business.common.data.CouponsData;
import cn.sc.allinpay.allfavour.business.common.data.OrderResult;
import cn.sc.allinpay.allfavour.business.common.data.SpOrderInfo;

/**
 * 收银台 卡券电子钱包核销
 * author：pany
 * on 2017/12/5 14:44
 */
public class CashierSellModel extends BaseModel {
    /**
     * 会员核销订单创建
     * 包括：优惠，卡券，电子钱包
     *
     * @param authCode    会员动态码 卡号
     * @param totAmt      订单总金额
     * @param txnAmt      消费金额
     * @param coupons     使用券
     * @param couponAmt   用券总金额
     * @param rightsAmt   会员权益优惠金额
     * @param actulAmt    实付金额
     * @param oilType     油品号
     */
    public void reqSellOrder(String authCode, String totAmt, String txnAmt, List<CouponsData> coupons,
                             String couponAmt, String rightsAmt, String actulAmt, String oilType, final MpCallBack<OrderResult, String> mpCallBack) {
        RequestManager.reqSellOrder(authCode,totAmt,txnAmt, coupons, couponAmt,rightsAmt,actulAmt,oilType, new AppRequest.RequestCall() {
            @Override
            protected void onSuccess(JSONObject response) {
                OrderResult orderResult = response.getObject("data", OrderResult.class);
                mpCallBack.onSuccess(orderResult);
            }

            @Override
            public void onFailure(JSONObject response, String message) {
                mpCallBack.onFailure(response != null ? response.toString() : null, message);
            }
        });
    }

    /**
     * 创建商点订单
     *
     */
    public void spCreateOrder(String amount, String outOrderNo, final MpCallBack<SpOrderInfo, String> mpCallBack) {
        RequestManager.spCreateOrder(amount, outOrderNo, new AppRequest.PosRequestCall() {
            @Override
            protected void onSuccess(JSONObject response) {
                SpOrderInfo orderInfo = response.getObject("data", SpOrderInfo.class);
                mpCallBack.onSuccess(orderInfo);
            }
            @Override
            public void onFailure(JSONObject response, String message) {
                mpCallBack.onFailure(response != null ? response.toString() : null, message);
            }
        });
    }
}
